<template>
  <div class="app-container">
    <el-form
      v-if="false"
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="学生评分" prop="studentEvaluation">
        <el-select
          v-model="queryParams.studentEvaluation"
          placeholder="请选择学生评分"
          clearable
        >
          <el-option
            v-for="dict in dict.type.evaluation"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学生评语" prop="studentComments">
        <el-input
          v-model="queryParams.studentComments"
          placeholder="请输入学生评语"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教师评分" prop="tutorsEvaluation">
        <el-select
          v-model="queryParams.tutorsEvaluation"
          placeholder="请选择教师评分"
          clearable
        >
          <el-option
            v-for="dict in dict.type.evaluation"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="教师评语" prop="tutorsComments">
        <el-input
          v-model="queryParams.tutorsComments"
          placeholder="请输入教师评语"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课程评分" prop="coursesEvalutaion">
        <el-select
          v-model="queryParams.coursesEvalutaion"
          placeholder="请选择课程评分"
          clearable
        >
          <el-option
            v-for="dict in dict.type.evaluation"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="课程评语" prop="coursesComments">
        <el-input
          v-model="queryParams.coursesComments"
          placeholder="请输入课程评语"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科研评分" prop="researchEvaluation">
        <el-select
          v-model="queryParams.researchEvaluation"
          placeholder="请选择科研评分"
          clearable
        >
          <el-option
            v-for="dict in dict.type.evaluation"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="科研评语" prop="researchComments">
        <el-input
          v-model="queryParams.researchComments"
          placeholder="请输入科研评语"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="论文评分" prop="papersEvaluation">
        <el-select
          v-model="queryParams.papersEvaluation"
          placeholder="请选择论文评分"
          clearable
        >
          <el-option
            v-for="dict in dict.type.evaluation"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="论文评语" prop="papersComments">
        <el-input
          v-model="queryParams.papersComments"
          placeholder="请输入论文评语"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="获奖评分" prop="awardsEvaluation">
        <el-select
          v-model="queryParams.awardsEvaluation"
          placeholder="请选择获奖评分"
          clearable
        >
          <el-option
            v-for="dict in dict.type.evaluation"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="获奖评语" prop="awardsComments">
        <el-input
          v-model="queryParams.awardsComments"
          placeholder="请输入获奖评语"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row vif="false" :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['Evaluation:evaluation:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['Evaluation:evaluation:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['Evaluation:evaluation:remove']"
          >删除</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Evaluation:evaluation:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="evaluationList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="评价ID" align="center" prop="resultId" /> -->
      <el-table-column label="学位点" align="center" prop="pointName" />
      <el-table-column label="学生评分" align="center" prop="studentEvaluation">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.evaluation"
            :value="scope.row.studentEvaluation"
          />
        </template>
      </el-table-column>
      <el-table-column label="学生评语" align="center" prop="studentComments">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <template #content>
              <div style="white-space: normal; max-width: 200px">
                {{ scope.row.studentComments }}
              </div>
            </template>
            <div class="ellipsis">{{ scope.row.studentComments }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="教师评分" align="center" prop="tutorsEvaluation">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.evaluation"
            :value="scope.row.tutorsEvaluation"
          />
        </template>
      </el-table-column>
      <el-table-column label="教师评语" align="center" prop="tutorsComments">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <template #content>
              <div style="white-space: normal; max-width: 200px">
                {{ scope.row.tutorsComments }}
              </div>
            </template>
            <div class="ellipsis">{{ scope.row.tutorsComments }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="课程评分" align="center" prop="coursesEvalutaion">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.evaluation"
            :value="scope.row.coursesEvalutaion"
          />
        </template>
      </el-table-column>
      <el-table-column label="教师评语" align="center" prop="tutorsComments">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <template #content>
              <div style="white-space: normal; max-width: 200px">
                {{ scope.row.tutorsComments }}
              </div>
            </template>
            <div class="ellipsis">{{ scope.row.tutorsComments }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column
        label="科研评分"
        align="center"
        prop="researchEvaluation"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.evaluation"
            :value="scope.row.researchEvaluation"
          />
        </template>
      </el-table-column>
      <el-table-column label="科研评语" align="center" prop="researchComments">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <template #content>
              <div style="white-space: normal; max-width: 200px">
                {{ scope.row.researchComments }}
              </div>
            </template>
            <div class="ellipsis">{{ scope.row.researchComments }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="论文评分" align="center" prop="papersEvaluation">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.evaluation"
            :value="scope.row.papersEvaluation"
          />
        </template>
      </el-table-column>
      <el-table-column label="论文评语" align="center" prop="papersComments">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <template #content>
              <div style="white-space: normal; max-width: 200px">
                {{ scope.row.papersComments }}
              </div>
            </template>
            <div class="ellipsis">{{ scope.row.papersComments }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="获奖评分" align="center" prop="awardsEvaluation">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.evaluation"
            :value="scope.row.awardsEvaluation"
          />
        </template>
      </el-table-column>
      <el-table-column label="获奖评语" align="center" prop="awardsComments">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <template #content>
              <div style="white-space: normal; max-width: 200px">
                {{ scope.row.awardsComments }}
              </div>
            </template>
            <div class="ellipsis">{{ scope.row.awardsComments }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改评分对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生评分" prop="studentEvaluation">
          <el-select
            v-model="form.studentEvaluation"
            placeholder="请选择学生评分"
          >
            <el-option
              v-for="dict in dict.type.evaluation"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生评语" prop="studentComments">
          <el-input
            v-model="form.studentComments"
            placeholder="请输入学生评语"
          />
        </el-form-item>
        <el-form-item label="教师评分" prop="tutorsEvaluation">
          <el-select
            v-model="form.tutorsEvaluation"
            placeholder="请选择教师评分"
          >
            <el-option
              v-for="dict in dict.type.evaluation"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="教师评语" prop="tutorsComments">
          <el-input
            v-model="form.tutorsComments"
            placeholder="请输入教师评语"
          />
        </el-form-item>
        <el-form-item label="课程评分" prop="coursesEvalutaion">
          <el-select
            v-model="form.coursesEvalutaion"
            placeholder="请选择课程评分"
          >
            <el-option
              v-for="dict in dict.type.evaluation"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="课程评语" prop="coursesComments">
          <el-input
            v-model="form.coursesComments"
            placeholder="请输入课程评语"
          />
        </el-form-item>
        <el-form-item label="科研评分" prop="researchEvaluation">
          <el-select
            v-model="form.researchEvaluation"
            placeholder="请选择科研评分"
          >
            <el-option
              v-for="dict in dict.type.evaluation"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="科研评语" prop="researchComments">
          <el-input
            v-model="form.researchComments"
            placeholder="请输入科研评语"
          />
        </el-form-item>
        <el-form-item label="论文评分" prop="papersEvaluation">
          <el-select
            v-model="form.papersEvaluation"
            placeholder="请选择论文评分"
          >
            <el-option
              v-for="dict in dict.type.evaluation"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="论文评语" prop="papersComments">
          <el-input
            v-model="form.papersComments"
            placeholder="请输入论文评语"
          />
        </el-form-item>
        <el-form-item label="获奖评分" prop="awardsEvaluation">
          <el-select
            v-model="form.awardsEvaluation"
            placeholder="请选择获奖评分"
          >
            <el-option
              v-for="dict in dict.type.evaluation"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="获奖评语" prop="awardsComments">
          <el-input
            v-model="form.awardsComments"
            placeholder="请输入获奖评语"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listEvaluation,
  getEvaluation,
  delEvaluation,
  addEvaluation,
  updateEvaluation,
} from "@/api/Evaluation/evaluation";

export default {
  name: "Evaluation",
  dicts: ["evaluation"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评分表格数据
      evaluationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentEvaluation: null,
        studentComments: null,
        tutorsEvaluation: null,
        tutorsComments: null,
        coursesEvalutaion: null,
        coursesComments: null,
        researchEvaluation: null,
        researchComments: null,
        papersEvaluation: null,
        papersComments: null,
        awardsEvaluation: null,
        awardsComments: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentEvaluation: [
          {
            required: true,
            message: "学生评分不能为空",
            trigger: "change",
          },
        ],
        tutorsEvaluation: [
          {
            required: true,
            message: "教师评分不能为空",
            trigger: "change",
          },
        ],
        coursesEvalutaion: [
          {
            required: true,
            message: "课程评分不能为空",
            trigger: "change",
          },
        ],
        researchEvaluation: [
          {
            required: true,
            message: "科研评分不能为空",
            trigger: "change",
          },
        ],
        papersEvaluation: [
          {
            required: true,
            message: "论文评分不能为空",
            trigger: "change",
          },
        ],
        awardsEvaluation: [
          {
            required: true,
            message: "获奖评分不能为空",
            trigger: "change",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询评分列表 */
    getList() {
      this.loading = true;
      listEvaluation(this.queryParams).then((response) => {
        this.evaluationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        resultId: null,
        pointId: null,
        expertId: null,
        studentEvaluation: null,
        studentComments: null,
        tutorsEvaluation: null,
        tutorsComments: null,
        coursesEvalutaion: null,
        coursesComments: null,
        researchEvaluation: null,
        researchComments: null,
        papersEvaluation: null,
        papersComments: null,
        awardsEvaluation: null,
        awardsComments: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.resultId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加评分";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const resultId = row.resultId || this.ids;
      getEvaluation(resultId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改评分";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.resultId != null) {
            updateEvaluation(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEvaluation(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const resultIds = row.resultId || this.ids;
      this.$modal
        .confirm('是否确认删除评分编号为"' + resultIds + '"的数据项？')
        .then(function () {
          return delEvaluation(resultIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "Evaluation/evaluation/export",
        {
          ...this.queryParams,
        },
        `evaluation_${new Date().getTime()}.xlsx`
      );
    },
  },

  filters: {
    ellipsis(value) {
      if (!value) return "";
      return value.length > 20 ? value.slice(0, 20) + "..." : value;
    },
  },
};
</script>

<style scoped>
.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px; /* 根据需要调整最大宽度 */
}

/* 自定义 el-tooltip 的样式 */
.el-tooltip__popper {
  background-color: white;
  border: 1px solid #ebeef5;
}
</style>
